define(["jquery", "easy-admin"], function ($, ea) {
    function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
                return decodeURI(pair[1]);  //处理中文显示异常
            }
        }
    }

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        wait_url: 'wait_pay',
        payment_url: 'payment',
        refuse_url: 'mall.audit_status1/refuse',
        withdraw_url: 'mall.withdraw_user/withdraw',
        submit_payment_url: 'mall.audit_status1/submit_payment',
    };

    var Controller = {

        submit_payment: function () {
            ea.listen();
        },
        refuse: function () {
            ea.listen();
        },
        wait_pay: function () {
            ea.table.render({
                init: init,
                elem: '#paymentTable',
                url: init.wait_url,
                toolbar: ['refresh'],
                cols: [[
                    {field: 'user.name', title: '姓名'},
                    {field: 'user.mobile', title: '电话号码'},
                    {field: 'user.avatar_url', title: '头像', templet: ea.table.image, search: false},
                    {field: 'amount', title: '提现金额', templet: ea.table.price, search: false},
                    {
                        field: 'type',
                        title: '提现方式',
                        selectList: {
                            // 0: '未支付',
                            1: '微信收款码',
                            2: '支付宝收款码',
                            3: '支付宝账号',
                        },
                        // templet: ea.table.switch
                    },
                    {
                        field: 'status',
                        title: '提现状态',
                        selectList: {
                            0: '未审核',
                            1: '审核通过打款中',
                            2: '已打款',
                            10: '已驳回',
                        },
                        // templet: ea.table.switch
                    },
                    {field: 'create_time', minWidth: 80, title: '申请时间', search: 'false'},
                    {
                        field: 'ea_mall_withdraw_record-create_time_left',
                        minWidth: 80,
                        title: '创建开始时间',
                        search: 'rangeLeft',
                        hide: true,
                        searchOp: 'rangeLeft'
                    },
                    {
                        field: 'ea_mall_withdraw_record-create_time_right',
                        minWidth: 80,
                        title: '创建结束时间',
                        search: 'rangeRight',
                        hide: true,
                        searchOp: 'rangeRight'
                    },
                    {field: 'approve_time', minWidth: 80, title: '审核通过时间', search: false},
                    {
                        field: 'approve_time_left',
                        minWidth: 80,
                        title: '审核开始时间',
                        search: 'rangeLeft',
                        hide: true,
                        searchOp: 'rangeLeft'
                    },
                    {
                        field: 'approve_time_right',
                        minWidth: 80,
                        title: '审核结束时间',
                        search: 'rangeRight',
                        hide: true,
                        searchOp: 'rangeRight'
                    },
                    {field: 'approve_user', minWidth: 80, title: '审核人', search: false},
                    {
                        width: 250, title: '操作', templet: function (row) {
                            var operat = []
                            if (row.status === 1) {
                                operat.push(
                                    [{
                                        text: '确认打款',
                                        field: 'id',
                                        url: init.submit_payment_url,
                                        method: 'open',
                                        auth: 'payment',
                                        class: 'layui-btn layui-btn-xs layui-btn-success',
                                    }],
                                )
                                operat.push(
                                    [{
                                        text: '驳回打款',
                                        field: 'id',
                                        url: init.refuse_url,
                                        method: 'open',
                                        auth: 'refuse',
                                        class: 'layui-btn layui-btn-xs layui-btn-fail',
                                    }],
                                )
                            }

                            return ea.table.tool(row, {
                                init, // 初始化的数据变量
                                operat: operat
                            }); // 其他状态下 没有操作按钮返回空字符串即可
                        }
                    },
                ]],
            });

            ea.listen();
        },
    };
    $("body").on('click', "#approve", function () {
        //元素移除前校验是否被引用
        $('#but').show()
        $('#remark').show()
        $('#line').show()
        return false
    });
    return Controller;
});
